﻿// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.DataRow
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 8E14765A-6610-409A-BA36-099A0642905D
// Assembly location: E:\git\ALLIDA\windll\infocard.exe

using Microsoft.InfoCards.Diagnostics;

namespace Microsoft.InfoCards
{
  internal class DataRow
  {
    private string m_instanceId;
    private string m_sourceId;
    private int m_localId;
    private int m_objectType;
    private long m_lastChange;
    private int m_objectSize;
    private GlobalId m_globalId;
    private byte[] m_buffer;
    private DataRowIndexBuffer m_indexBuffer;

    public DataRow()
      : this((string) null, (string) null)
    {
    }

    private DataRow(string instanceId, string sourceId)
    {
      this.m_instanceId = instanceId;
      this.m_sourceId = sourceId;
      this.m_indexBuffer = new DataRowIndexBuffer();
    }

    public GlobalId GlobalId
    {
      get
      {
        return this.m_globalId;
      }
      set
      {
        if (GlobalId.Empty == value)
          throw InfoCardTrace.ThrowHelperArgumentNull(nameof (value));
        this.m_globalId = value;
        this.SetIndexValue("ix_globalid", (object) value);
      }
    }

    public string InstanceId
    {
      get
      {
        return this.m_instanceId;
      }
      internal set
      {
        this.m_instanceId = value;
      }
    }

    public string SourceId
    {
      get
      {
        return this.m_sourceId;
      }
      internal set
      {
        this.m_sourceId = value;
      }
    }

    public long LastChange
    {
      get
      {
        return this.m_lastChange;
      }
      internal set
      {
        this.m_lastChange = value;
      }
    }

    public int LocalId
    {
      get
      {
        return this.m_localId;
      }
      internal set
      {
        this.m_localId = value;
      }
    }

    public int ObjectType
    {
      get
      {
        return this.m_objectType;
      }
      set
      {
        this.m_objectType = value;
        this.SetIndexValue("ix_objecttype", (object) value);
      }
    }

    internal DataRowIndexBuffer IndexBuffer
    {
      get
      {
        return this.m_indexBuffer;
      }
    }

    public void SetDataField(byte[] buffer)
    {
      this.SetDataField(buffer, buffer.Length);
    }

    public void SetDataField(byte[] buffer, int size)
    {
      this.m_buffer = buffer;
      this.m_objectSize = size;
    }

    public byte[] GetDataField()
    {
      return this.m_buffer;
    }

    public void SetMultiIndexValue(string name, params object[][] multiValues)
    {
      IndexObject[] indexObjects = new IndexObject[multiValues.Length];
      for (int index = 0; index < multiValues.Length; ++index)
        indexObjects[index] = new IndexObject(multiValues[index]);
      this.m_indexBuffer.SetIndexValues(name, indexObjects);
    }

    public void SetIndexValue(string name, params object[] values)
    {
      object[][] objArray = new object[values.Length][];
      for (int index = 0; index < objArray.Length; ++index)
        objArray[index] = new object[1]{ values[index] };
      this.SetMultiIndexValue(name, objArray);
    }

    internal static unsafe DataRow Create(EncryptedObjectHeader* pHeader, DataSource source)
    {
      return new DataRow(source.InstanceId, source.SourceId)
      {
        LastChange = pHeader->LastChange,
        ObjectType = pHeader->ObjectType,
        LocalId = pHeader->LocalId,
        GlobalId = pHeader->GlobalId,
        m_objectSize = pHeader->DataSize
      };
    }
  }
}
